<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <base href="<%=url%>">
    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://lib.baomitu.com/layui/2.6.5/layui.min.js"></script>
    <link href="https://lib.baomitu.com/layui/2.6.5/css/layui.min.css" rel="stylesheet">
    <style>
    </style>

</head>
<body>
<div class="layui-main">
    <blockquote class="layui-elem-quote">列表</blockquote>
    <a style="margin-left: 50px"><span style="font-size: 18px;margin-right: 10px">订单编号查询:</span><input type="text" placeholder="请输入订单编号" id="input-id" style="height: 30px"></a>
    <a style="margin-left: 50px"><span style="font-size: 18px;margin-right: 10px">药品名称查询:</span><input type="text" placeholder="请输入药品名称" id="input-ypname" style="height: 30px"></a>
    <button  style="height: 30px;background-color: #1e9fff;color: whitesmoke;width: 60px;border:1px #1e9fff; border-radius: 4px" id="select_id_ypName">搜索</button>

    <table id="tbl" lay-filter="tbl"></table>
</div>

<script>
    //遍历下拉框内容
    $(function () {
        $.get("/medicine/SelectUnit",function (date,res) {
            if(res=="success"){
                $(".unitid").empty();
                for (let i = 0; i < date.length; i++) {
                    $(".unitid").append("<option value="+date[i].unitid+">"+date[i].unitname+"</option>")

                }
            }
        });
        setTimeout(function () {
            $.get("/medicine/SelectHome",function (date,res) {
                if(res=="success"){
                    $(".yfid").empty();
                    for (let i = 0; i < date.length; i++) {
                        $(".yfid").append("<option value="+date[i].yfid+">"+date[i].yfname+"</option>")

                    }
                }
            });
        },500)

    })
    //设置时间格式
    function myDateFomat(t){
        let date=new Date(t);
        let y=date.getFullYear();
        let m=(date.getMonth()+1).toString().padStart(2,"0");
        let d=date.getDate().toString().padStart(2,"0");
        let h=date.getHours().toString().padStart(2,"0");
        let f=date.getMinutes().toString().padStart(2,"0");
        let s=date.getSeconds().toString().padStart(2,"0");
        return y+"-"+m+"-"+d+" "+h+":"+f+":"+s;
    }
    layui.use(['jquery', 'table', 'layer', 'form'], function () {
        var $ = layui.$;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        table.render({
            elem: '#tbl',
            url: '/receipts/selectAll',
            method: 'get',
            initSort: { //排序
                field: 'account' //排序字段，对应 cols 设定的各字段名
                , type: 'asc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
            },
            cols: [[
                {field: 'id', title: '编号', width: 60},
                {field: 'ypid', title: '药品编号', width: 90},
                {field: 'ypname', title: '药品名称', width: 150},
                {field: 'normsid', title: '药品规格', width: 100},
                {field: 'unitid', title: '药品单位', templet:function (d) {
                        return d.unit && d.unit.unitname
                    },width: 88},
                {field: 'jprice', title: '药品进价', width: 88},
                {field: 'price', title: '药品售价', width: 88},
                {field: 'jnum', title: '进货数量', width: 88},
                {field: 'yfid', title: '药房编号', templet:function (d) {
                        return d.dispensary && d.dispensary.yfname
                    },width: 98},
                {field: 'sname', title: '申请人', width: 90},
                {field: 'stime', title: '申请时间', width: 127, templet: "<div>{{layui.util.toDateString(d.stime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'shtime', title: '审核时间', width: 127, templet: "<div>{{layui.util.toDateString(d.shtime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'shname', title: '审核人', width: 90},
                {field: 'revenue', title: '利润', width: 90},
                {field: 'notes', title: '备注', width: 127}
            ]],
            page: {
                limit: 5,//指定每页显示的条数
                limits: [5, 10, 20, 40, 50, 60, 80, 100]//每页条数的选中
            }//开启分页

            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            },
            // 表格容器id，用于表格重载
            id: 'tbl'
        });
        //精确查询  根据jid查询
        $("#select_id_ypName").click(function () {
            var id=$("#input-id").val();
            var ypname=$("#input-ypname").val();
            table.render({
                elem: '#tbl',
                url: '/receipts/select_rec?id='+id+'&ypname='+ypname,
                method: 'get',
                cols: [[
                    {field: 'id', title: '编号', width: 60},
                    {field: 'ypid', title: '药品编号', width: 90},
                    {field: 'ypname', title: '药品名称', width: 150},
                    {field: 'normsid', title: '药品规格', width: 100},
                    {field: 'unitid', title: '药品单位', templet:function (d) {
                            return d.unit && d.unit.unitname
                        },width: 88},
                    {field: 'jprice', title: '药品进价', width: 88},
                    {field: 'price', title: '药品售价', width: 88},
                    {field: 'jnum', title: '进货数量', width: 88},
                    {field: 'yfid', title: '药房编号', templet:function (d) {
                            return d.dispensary && d.dispensary.yfname
                        },width: 98},
                    {field: 'sname', title: '申请人', width: 90},
                    {field: 'stime', title: '申请时间', width: 127, templet: "<div>{{layui.util.toDateString(d.stime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                    {field: 'shtime', title: '审核时间', width: 127, templet: "<div>{{layui.util.toDateString(d.shtime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                    {field: 'shname', title: '审核人', width: 90},
                    {field: 'revenue', title: '利润', width: 90},
                    {field: 'notes', title: '备注', width: 127}
                ]],

                page:{
                    limit:5,//指定每页显示的条数
                    limits:[5,10,20,40,50,60,80,100]//每页条数的选中
                }//开启分页

                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                    var result;
                    if (this.page.curr) {
                        result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                    }
                    else {
                        result = res.data.slice(0, this.limit);
                    }
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": result //解析数据列表
                    };
                },
                // 表格容器id，用于表格重载
                id: 'tbl'
            });
        })

    })
</script>
</body>
</html>